package com.yzh.croom.mapper;

import com.yzh.croom.model.domain.VRoom;
import com.yzh.croom.model.domain.Week;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface VRoomMapper {

    @Select("select * from tb_vroom ")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "room_id", property = "roomInfo", many = @Many(
                    select = "com.yzh.croom.mapper.RoomMapper.getRoomById",
                    fetchType = FetchType.LAZY
            )),
            @Result(column = "week_id", property = "week", many = @Many(
                    select = "com.yzh.croom.mapper.WeekMapper.getWeekById",
                    fetchType = FetchType.LAZY
            )),
            @Result(column = "time_id", property = "time", many = @Many(
                    select = "com.yzh.croom.mapper.CourseTimeMapper.getCourseTimeById",
                    fetchType = FetchType.LAZY
            ))
    })
    public List<VRoom> getVroom();

    @Select("select * from tb_vroom where room_id = #{roomId} and status = 0")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "room_id", property = "roomInfo", many = @Many(
                    select = "com.yzh.croom.mapper.RoomMapper.getRoomById",
                    fetchType = FetchType.LAZY
            )),
            @Result(column = "week_id", property = "week", many = @Many(
                    select = "com.yzh.croom.mapper.WeekMapper.getWeekById",
                    fetchType = FetchType.LAZY
            )),
            @Result(column = "time_id", property = "time", many = @Many(
                    select = "com.yzh.croom.mapper.CourseTimeMapper.getCourseTimeById",
                    fetchType = FetchType.LAZY
            ))
    })
    public List<VRoom> getVroomById(String roomId);

    @Insert("insert into tb_vroom (room_id,week_id,time_id,status) values (#{roomId},#{weekId},#{timeId},#{status})")
    public int addVroom(VRoom vRoom);

    @Select("SELECT room_id FROM `tb_vroom` GROUP BY room_id")
    public List<VRoom> getVRoomGroupById();

    @Select("select week_id from tb_vroom where room_id = #{roomId} group by week_id")
    @Results({
            @Result(column = "week_id", property = "week", many = @Many(
                    select = "com.yzh.croom.mapper.WeekMapper.getWeekById",
                    fetchType = FetchType.LAZY
            ))
    })
    public List<VRoom> getVroomWeekGroupById(String roomId);
}
